package com.huiquan.medicine.dao;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.huiquan.framework.base.BaseDao;
import com.huiquan.icd.domain.IcdWeatherDisease;
import com.huiquan.medicine.entity.DiMedicineGroup;
import com.huiquan.medicine.entity.MedicineGroup;
import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * 药品 DAO
 *
 * @author leo
 * @time 2017年4月5日 下午5:52:12
 */
@Repository
public class MedicineDao extends BaseDao {

	@Resource(name = "sqlMapClient")
	private SqlMapClient sqlMapClient;

	public static final String space = "MEDICINE.";

	/**
	 * 检索药品分组的数量
	 * 
	 * @param params
	 * @return
	 */
	public int selectMedicineGroupCount(Map<String, Object> params) {
		return (int) this.object(space + "SELECT_MEDICINE_GROUP_COUNT", params, sqlMapClient);
	}

	/**
	 * 检索疾病药品分组的数量
	 * 
	 * @param params
	 * @return
	 */
	public int selectDiMedicineGroupCount(Map<String, Object> params) {
		return (int) this.object(space + "SELECT_DI_MEDICINE_GROUP_COUNT", params, sqlMapClient);
	}

	/**
	 * 检索药品分组列表
	 * 
	 * @param params
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<MedicineGroup> selectMedicineGroupList(Map<String, Object> params) {
		return (List<MedicineGroup>) this.list(space + "SELECT_MEDICINE_GROUP_LIST", params, sqlMapClient);
	}

	/**
	 * 检索疾病药品分组列表
	 * 
	 * @param params
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<DiMedicineGroup> selectDiMedicineGroupList(Map<String, Object> params) {
		return (List<DiMedicineGroup>) this.list(space + "SELECT_DI_MEDICINE_GROUP_LIST", params, sqlMapClient);
	}

	/**
	 * 检索药品分组列表用于导出
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<MedicineGroup> selectMedicineGroupListToExport() {
		return (List<MedicineGroup>) this.list(space + "SELECT_MEDICINE_GROUP_LIST_TO_EXPORT", sqlMapClient);
	}
	
	/**
	 * 检索疾病药品分组列表用于导出
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<DiMedicineGroup> selectDiMedicineGroupListToExport() {
		return (List<DiMedicineGroup>) this.list(space + "SELECT_DI_MEDICINE_GROUP_LIST_TO_EXPORT", sqlMapClient);
	}

	/**
	 * 插入一条药品分组
	 * 
	 * @param entity
	 */
	public void insertMedicineGroup(MedicineGroup entity) {
		this.insert(space + "INSERT_MEDICINE_GROUP", entity, sqlMapClient);
	}

	/**
	 * 插入一条疾病药品分组
	 * 
	 * @param entity
	 */
	public void insertDiMedicineGroup(DiMedicineGroup entity) {
		this.insert(space + "INSERT_DI_MEDICINE_GROUP", entity, sqlMapClient);
	}
	
	/**
	 * 批量导入 疾病药品分组
	 * 
	 * @param entity
	 */
	public void batchInsertDiMedicineGroup(List<DiMedicineGroup> insertList) {
		this.insert(space + "BATCH_INSERT_DI_MEDICINE_GROUP", insertList, sqlMapClient);
	}

	/**
	 * 根据序列检索一条药品分组
	 * 
	 * @param seq
	 * @return
	 */
	public MedicineGroup selectMedicineGroupBySeq(int seq) {
		return (MedicineGroup) this.object(space + "SELECT_MEDICINE_GROUP_BY_SEQ", seq, sqlMapClient);
	}

	/**
	 * 根据序列检索一条疾病药品分组
	 * 
	 * @param seq
	 * @return
	 */
	public DiMedicineGroup selectDiMedicineGroupBySeq(int seq) {
		return (DiMedicineGroup) this.object(space + "SELECT_DI_MEDICINE_GROUP_BY_SEQ", seq, sqlMapClient);
	}

	/**
	 * 更新一条药品分组
	 * 
	 * @param entity
	 */
	public void updateMedicineGroup(MedicineGroup entity) {
		this.update(space + "UPDATE_MEDICINE_GROUP", entity, sqlMapClient);
	}
	
	/**
	 * 更新一条疾病药品分组
	 * 
	 * @param entity
	 */
	public void updateDiMedicineGroup(DiMedicineGroup entity) {
		this.update(space + "UPDATE_DI_MEDICINE_GROUP", entity, sqlMapClient);
	}

	/**
	 * 根据序列删除一条药品分组
	 * 
	 * @param seq
	 */
	public void deleteMedicineGroupBySeq(int seq) {
		this.delete(space + "DELETE_MEDICINE_GROUP_BY_SEQ", seq, sqlMapClient);
	}
	
	/**
	 * 根据序列删除一条疾病药品分组
	 * 
	 * @param seq
	 */
	public void deleteDiMedicineGroupBySeq(int seq) {
		this.delete(space + "DELETE_DI_MEDICINE_GROUP_BY_SEQ", seq, sqlMapClient);
	}
	
	/**
	 * 删除全部疾病药品分组
	 * 
	 * @param seq
	 */
	public void deleteDiMedicineGroup() {
		this.delete(space + "DELETE_DI_MEDICINE_GROUP",sqlMapClient);
	}
	
	/**
	 * 删除全部药品分组
	 * 
	 * @param seq
	 */
	public void deleteMedicineGroup() {
		this.delete(space + "DELETE_MEDICINE_GROUP",sqlMapClient);
	}

	/**
	 * 根据name检索得到对应的疾病的count
	 * 
	 * @param name
	 * @return
	 */
	public int selectIcdDiseaseCountByName(String name) {
		return (int) this.object(space + "SELECT_ICD_DISEASE_COUNT_BY_NAME", name, sqlMapClient);
	}
	
// 导出
	public List<Map<String, Object>> getmedicinegroup(Map<String, Object> param) {

		return (List<Map<String, Object>>)list(space + "EXPORT_MEDICINE_GROUP", param, sqlMapClient);
	}

}
